#include <ps2.h>

PS2 mouse(6, 5);

void setup()
{
  Serial.begin(9600);
  mouse.write(0xff);  // reset
  mouse.read();  // ack byte
  mouse.read();  // blank */
  mouse.read();  // blank */
  mouse.write(0xf0);  // remote mode
  mouse.read();  // ack
  delayMicroseconds(100);
}

void loop()
{
  /* get a reading from the mouse */
  mouse.write(0xeb);  // give me data!
  mouse.read();      // ignore ack
  char mstat = mouse.read();
  int x = mouse.read();
  int y = mouse.read();
  
  // if negative, two's complement
  if (0x10&mstat) x|=0xFF00;
  if (0x20&mstat) y|=0xFF00;
}
